package com.raising.modules.sys.controller;//package com.raising.system.modules.admin.controller;
//
//import cn.raising.common.Page;
//import cn.raising.common.StaticParam;
//import cn.raising.common.utils.ClientUtil;
//import cn.raising.common.utils.ErrorList;
//import cn.raising.common.utils.Exceptions;
//import cn.raising.sys.entity.MsgReceive;
//import cn.raising.sys.entity.MsgSend;
//import cn.raising.sys.entity.User;
//import cn.raising.sys.entity.enums.MsgEnum;
//import cn.raising.sys.service.MsgReceiveService;
//import com.google.common.collect.Maps;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Map;
//
///**
// * 短消息接口
// * @author gaoy
// * 2017 2017-5-25 下午2:43:16
// */
//@RestController
//@RequestMapping("${restPath}/sys/msgReceive")
//public class MsgRest extends ClientUtil{
//
//	@Autowired
//    private MsgReceiveService msgReceiveService;
//
//
//    /**
//     * 查询消息
//     * @author gaoy
//     * 2017 2017-5-25 下午3:14:25
//     * @param request
//     * @param response
//     * @throws Exception
//     */
//    @RequestMapping(value = "/selectMsgPage", method = RequestMethod.POST)
//    public void selectMsgPage(HttpServletRequest request,HttpServletResponse response) throws Exception{
//    	String jsonData  = "";
//    	Map<String,Object> map =  Maps.newHashMap();
//        try{
//        	/**获取参数*/
//        	Map<String, Object> params = getParameterMap(request, response);
//        	String userId = this.passNull(params.get("userId"));
//        	Integer pageSize = this.parseInt(params.get("pageSize"));
//        	Integer pageNo = this.parseInt(params.get("pageNo"));
//        	/**生产数据*/
//        	Page<MsgReceive> page = new Page<MsgReceive>();
//        	MsgReceive msgReceive = new MsgReceive();
//        	User user = new User();
//        	user.setId(userId);
//        	//status被初始化为0未读了，应该置为null，则可查询所有消息
//        	msgReceive.setStatus(null);
//        	msgReceive.setUser(user);
//        	msgReceive.setMsgSend(new MsgSend());
//        	msgReceive.getMsgSend().setType(MsgEnum.notice);
//        	page.setPageSize(pageSize);
//        	page.setPageNo(pageNo);
//            page.setEntity(msgReceive);
//            page.setOrderBy("a.status,a.update_date desc,c.level desc");
//        	/**返回数据*/
//        	map.put("msgList", msgReceiveService.findPage(page));
//        	jsonData = this.getMsgJson(SUCCESS,map);
//        	flashDataToClient(response, jsonData);
//        }catch (Exception e){
//        	jsonData = this.getMsgJson(ERROR,ErrorList.CODE_ERROR,"查询消息失败");
//        	flashDataToClient(response, jsonData);
//            logger.error("查询消息接口调用失败",e.getMessage());
//            throw Exceptions.error(e);
//        }
//    }
//    /**
//     * 查询未读消息数量
//     * @author gaoy
//     * 2017 2017-5-25 下午3:14:21
//     * @param request
//     * @param response
//     * @throws Exception
//     */
//    @RequestMapping(value = "/selectNoReadMsgNum", method = RequestMethod.POST)
//    public void selectNoReadMsgNum(HttpServletRequest request,HttpServletResponse response) throws Exception{
//    	String jsonData  = "";
//    	Map<String,Object> map =  Maps.newHashMap();
//        try{
//        	/**获取参数*/
//        	Map<String, Object> params = getParameterMap(request, response);
//        	String userId = this.passNull(params.get("userId"));
//        	/**生产数据*/
//        	Page<MsgReceive> page = new Page<MsgReceive>();
//        	MsgReceive msgReceive = new MsgReceive();
//        	msgReceive.setUser(new User(userId));
//        	msgReceive.setMsgSend(new MsgSend());
//        	msgReceive.getMsgSend().setType(MsgEnum.notice);
//        	msgReceive.setStatus(StaticParam.NO+"");//状态 0未读 1已读
//            page.setEntity(msgReceive);
//        	/**返回数据*/
//        	map.put("msgNum", String.valueOf(msgReceiveService.count(page)));
//        	jsonData = this.getMsgJson(SUCCESS,map);
//        	flashDataToClient(response, jsonData);
//        }catch (Exception e){
//        	jsonData = this.getMsgJson(ERROR,ErrorList.CODE_ERROR,"查询未读消息数量失败");
//        	flashDataToClient(response, jsonData);
//            logger.error("查询未读消息数量接口调用失败",e.getMessage());
//            throw Exceptions.error(e);
//        }
//    }
//
//    /**
//     * 将未读消息置为已读：status改为1
//     * @author peijs
//     * @param request
//     * @param response
//     * @throws Exception
//     */
//    @RequestMapping(value = "/updateMsgToRead", method = RequestMethod.POST)
//    public void updateMsgToRead(HttpServletRequest request,HttpServletResponse response) throws Exception{
//    	String jsonData  = "";
//    	Map<String,Object> map =  Maps.newHashMap();
//        try{
//        	/**获取参数*/
//        	Map<String, Object> params = getParameterMap(request, response);
//        	String msgId = this.passNull(params.get("msgId"));
//        	/**生产数据*/
//        	MsgReceive msgReceive = new MsgReceive();
//        	msgReceive.setMsgId(msgId);
//        	msgReceive.setStatus(StaticParam.YES+"");//状态 0未读 1已读
//        	msgReceiveService.updateMsgToRead(msgReceive);
//        	/**返回数据*/
//        	map.put("success", "");
//        	jsonData = this.getMsgJson(SUCCESS,map);
//        	flashDataToClient(response, jsonData);
//        }catch (Exception e){
//        	jsonData = this.getMsgJson(ERROR,ErrorList.CODE_ERROR,"消息状态更新失败");
//        	flashDataToClient(response, jsonData);
//            logger.error("消息状态更新接口调用失败",e.getMessage());
//            throw Exceptions.error(e);
//        }
//    }
//
//}
